<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商家注册页面</title>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        .container h2 {
            margin-bottom: 20px;
            text-align: center;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        .form-group button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .form-group button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>商家注册</h2>
    <form id="merchantRegistrationForm">
        <div class="form-group">
            <label for="name">名称:</label>
            <input type="text" id="name" name="name" required>
        </div>
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" name="password" required>
        </div>
        <div class="form-group">
            <label for="confirmPassword">确认密码:</label>
            <input type="password" id="confirmPassword" name="confirmPassword" required>
        </div>
        <div class="form-group">
            <button type="submit">提交</button>
        </div>
    </form>
</div>

<script>
    document.getElementById('merchantRegistrationForm').addEventListener('submit', function(event) {
        event.preventDefault(); // 阻止表单默认提交行为

        var name = document.getElementById('name').value;
        var password = document.getElementById('password').value;
        var confirmPassword = document.getElementById('confirmPassword').value;

        if (password !== confirmPassword) {
            alert('密码和确认密码不匹配，请重新输入！');
        } else {
            // 在这里你可以添加发送数据到服务器的代码
            // 例如使用fetch或XMLHttpRequest发送POST请求
            alert('注册成功！');
            window.location.href = "login.html";

            let obj = {mname: name, mpassword: password};
            $.ajax({
                url: "merchant/add",
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(obj),
                success: function(data) {
                    console.log("1-------", data);
                },
                complete: function(data) {
                    console.log("2------", data);
                }
            });

            // 重置表单
            document.getElementById('merchantRegistrationForm').reset();
        }
    });
    // document.getElementById('merchantRegistrationForm').addEventListener('submit', function(event) {
    //     event.preventDefault(); // 阻止表单默认提交行为
    //
    //     var name = document.getElementById('name').value;
    //     var password = document.getElementById('password').value;
    //     var confirmPassword = document.getElementById('confirmPassword').value;
    //
    //     if (password !== confirmPassword) {
    //         alert('密码和确认密码不匹配，请重新输入！');
    //     } else {
    //         // 在这里你可以添加发送数据到服务器的代码
    //         // 例如使用fetch或XMLHttpRequest发送POST请求
    //         alert('注册成功！');
    //
    //         let obj = {mname:name,mpassword:password};
    //         $.ajax({
    //             url:"merchant/add",
    //             type:"POST",
    //             data:JSON.stringify(obj),
    //             success:function (data){
    //                 console.log("1-------",data);
    //             },
    //             complete:function (data){
    //                 console.log("2------",data);
    //
    //             }
    //         })
    //         // 重置表单
    //         document.getElementById('merchantRegistrationForm').reset();
    //     }
    // });
</script>
</body>
</html>